/**
 * 
 */
export default {
	state: {
		addressList: [{
					tel: '18796985061',
					name: '吴永杰',
					address: '江苏省常州市新北区',
					detail_address:"创意路创意软件园D座-0525-1",
					defualt_true: true
				}]
	},
	getters:{
		getDefaultAddress(state){
			return state.addressList.filter(v=>v.defualt_true);
		}
	},
	mutations: {
		setDefaultAddress(state, index) {
			let arr=state.addressList.filter(v => v.defualt_true);
			if(arr.length>0){
				arr[0].defualt_true = false
			}
			state.addressList[index].defualt_true = true;
		},
		addAddress(state, item) {
			if (item.defualt_true && state.addressList.length > 0) {
				state.addressList.some(v => {
					if (v.defualt_true) {
						v.defualt_true = false;
						return true;
					}
				})
			}else{
				item.defualt_true =true;
			}
			state.addressList.push(item);
			console.log(item)
			uni.showToast({
				title: "新增成功",
				success: () => {
					if(item.backType==0){
						uni.navigateTo({
							url: "/pages/take-address/take-address"
						})
					}else{
						uni.navigateTo({
							url:"../take-address/take-address?param=1"
						})
					}
					
				}
			})
			
		},
		deleteAddress(state, index) {
			uni.showModal({
				content: '确定删除该收货地址？',
				success: (res) => {
					if (res.confirm) {
						state.addressList.splice(index, 1);
					}
				}
			})

		}
	}
}
